﻿using DigDes.DSchool.SUPS.DataAccess.Database;
using DigDes.DSchool.SUPS.DataAccess.FileLoaders;
using DigDes.DSchool.SUPS.DataAccess.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DigDes.DSchool.SUPS.BusinessLogic
{
    public class FileLoaderBC
    {
        public void LoadMyFile(string filePath)
        {
            var loader = new Loader();
            try
            {
                // Проверяем длину первой строки файла
                if (!loader.Check(filePath)) throw new Exception();
            }
            catch(Exception)
            {
                Console.WriteLine("First line in a file has a wrong length\nPress any key to exit");
            }

            foreach (var row in loader.LoadFileRow(filePath))
            {
                FileLoaderDAC.LoadRowToDB(row);
            }
        }
    }
}
